# Maintainer: Ariel Axionl <i at axionl dot me>

_realname=zxing-cpp
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.0.0
pkgrel=1
pkgdesc='A multi-format linear/matrix barcode image processing library implemented in C++ (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://github.com/zxing-cpp/zxing-cpp'
license=('Apache')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
options=('staticlibs')
source=(https://github.com/zxing-cpp/zxing-cpp/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz)
sha256sums=('12b76b7005c30d34265fc20356d340da179b0b4d43d2c1b35bcca86776069f76')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
}

build() {
  # Shared Build
  [[ -d "build-${MSYSTEM}-shared" ]] && rm -rf "build-${MSYSTEM}-shared"

  mkdir -p ${srcdir}/build-${MSYSTEM}-shared
  cd ${srcdir}/build-${MSYSTEM}-shared

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
  -G"Ninja" \
  -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
  -DCMAKE_BUILD_TYPE=Release \
  -DBUILD_SHARED_LIBS=ON \
  -DBUILD_EXAMPLES=OFF \
  -DBUILD_BLACKBOX_TESTS=OFF \
  ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake.exe --build .

  # Static Build
  [[ -d "build-${MSYSTEM}-static" ]] && rm -rf "build-${MSYSTEM}-static"

  mkdir -p ${srcdir}/build-${MSYSTEM}-static
  cd ${srcdir}/build-${MSYSTEM}-static

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
  -G"Ninja" \
  -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
  -DCMAKE_BUILD_TYPE=Release \
  -DBUILD_SHARED_LIBS=OFF \
  -DBUILD_EXAMPLES=OFF \
  -DBUILD_BLACKBOX_TESTS=OFF \
  ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake.exe --build .
}

package() {
  # Static Install
  cd "${srcdir}/build-${MSYSTEM}-static"
  DESTDIR=${pkgdir} ${MINGW_PREFIX}/bin/cmake.exe --install .

  # Shared Install
  cd "${srcdir}/build-${MSYSTEM}-shared"
  DESTDIR=${pkgdir} ${MINGW_PREFIX}/bin/cmake.exe --install .

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
